package com.tich.program.controller;


import com.tich.constant.ResponseMessageConstant;
import com.tich.program.domain.dto.ProgramTicketUpdateDTO;
import com.tich.program.domain.dto.ProgramTicketsSaveDTO;
import com.tich.program.domain.vo.ProgramTicketSelectVO;
import com.tich.program.service.IProgramTicketService;
import com.tich.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 节目门票接口
 */
@Slf4j
@RestController
@RequestMapping("/program/ticket")
public class ProgramTicketController {

    @Autowired
    private IProgramTicketService iProgramTicketService;

    /**
     * 批量给节目添加门票
     * @param programTicketsSaveDTO
     * @return
     * */
    @PostMapping
    public Result saveProgramTickets(@RequestBody ProgramTicketsSaveDTO programTicketsSaveDTO){
        //TODO 判断是否是管理员
        log.info("批量给相关节目添加门票信息,{}", programTicketsSaveDTO);
        iProgramTicketService.saveProgramTickets(programTicketsSaveDTO);
        return Result.success(ResponseMessageConstant.SAVE_SUCCESS);
    }

    /**
     * 根据节目id查询节目门票信息
     * @param programId
     * @return
     * */
    @GetMapping
    public Result<List<ProgramTicketSelectVO>> selectProgramTickets(Long programId){
        log.info("根据节目id查询节目门票信息,programId:{}", programId);
        return Result.success(ResponseMessageConstant.QUERY_SUCCESS,
                iProgramTicketService.selectProgramTickets(programId));
    }

    /**
     * 修改节目门票信息
     * @param programTicketUpdateDTO
     * @return
     * */
    @PutMapping
    public Result updateProgramTicket(@RequestBody ProgramTicketUpdateDTO programTicketUpdateDTO){
        log.info("修改节目门票信息：{}",programTicketUpdateDTO);
        iProgramTicketService.updateProgramTicket(programTicketUpdateDTO);
        return Result.success(ResponseMessageConstant.UPDATE_SUCCESS);
    }

    /**
     * 根据id删除门票
     * @param id
     * @return
     * */
    @DeleteMapping
    public Result deleteProgramTickets(Long id){
        log.info("根据id删除门票:{}", id);
        iProgramTicketService.deleteProgramTickets(id);
        return Result.success(ResponseMessageConstant.DELETE_SUCCESS);
    }


}
